//
//  MYShopDetailsHeaderView.swift
//  MuYing
//
//  Created by tbb on 2019/7/29.
//  Copyright © 2019 TBB. All rights reserved.
//

import UIKit
import SDCycleScrollView
class MYShopDetailsHeaderView: UITableViewHeaderFooterView,SDCycleScrollViewDelegate {
    
    //@objc var selectIndexAction: ((_ index:Int) -> Void)?
    
    @objc var skuImageModel = YQPSkuInfoModel()
    
    @objc var imageUrlStrArr:[NSString]? {
        didSet {
            self.imgBannar.imageURLStringsGroup = imageUrlStrArr;
            
        }
    }
    
    lazy var countLb: UILabel = {
        let countLb = UILabel();
        countLb.textColor = .white;
        countLb.font = UIFont.systemFont(ofSize: 12, weight: .medium);
        countLb.text = "1/9";
        
        return countLb;
    }()
    @objc lazy var imgBannar: MyBaseCycleScrollView = {
        let imgBannar = MyBaseCycleScrollView(frame: self.bounds, imageNamesGroup: nil);
        imgBannar?.delegate = self;
        return imgBannar!;
    }()
    override init(reuseIdentifier: String?) {
        super.init(reuseIdentifier: reuseIdentifier);
        self.contentView.addSubview(self.imgBannar);
        self.imgBannar.mas_makeConstraints { (make) in
            make?.edges.mas_equalTo()(0);
        }
        
        self.contentView.addSubview(self.countLb);
        self.countLb.mas_makeConstraints({ (make) in
            make?.right.mas_equalTo()(-12);
            make?.bottom.mas_equalTo()(-12);
            make?.height.mas_equalTo()(17);
        });

    }
    
    /** 点击图片回调 */
    func cycleScrollView(_ cycleScrollView: SDCycleScrollView!, didSelectItemAt index: Int) {
        if let imageUrlStrArr = self.imageUrlStrArr {
            let imageBrowser = YQBaseImageBrowserVC.init(imageArrUrl: imageUrlStrArr , currentIndex: UInt(index), sourceObject: imgBannar);
            imageBrowser.currentPage = index;
            imageBrowser.show();
        }
        
    }
    
    /** 图片滚动回调 */
    func cycleScrollView(_ cycleScrollView: SDCycleScrollView!, didScrollTo index: Int) {

        countLb.text = String(format:"%d",index + 1) + kYQLSSwift("/") +  String(format:"%d",self.imageUrlStrArr?.count ?? 1)

    }
    
    @objc func setModel(_ model:YQPSkuInfoModel)
    {
        self.skuImageModel = model
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
